﻿#pragma once
#include <qobject.h>
#include <qsqldatabase.h>
#include <qsqlquery.h>
#include <qmessagebox.h>
#include <qdebug.h>
#include <QStringList>



class OpeDB :
	public QObject
{
	Q_OBJECT
public:
	explicit OpeDB(QObject* parent = 0);
	// static member function (singleton)
	// this class just have one object
	static OpeDB& getInstance();
	void init();

	~OpeDB();

	bool handleRegist(const char* name, const char* pwd);
	bool handleLogin(const char* name, const char* pwd);
	void handleOffline(const char* name, const char* pwd);
	//返回-1 用户不存在；返回0 用户不在线；返回1 用户在线
	int handleSearchUsr(const char* name);
	void handleRecover();   //**** 重置数据库在线状态 ****
	QStringList handleAllOnline();
	//返回-2 系统错误；返回2 已经是好友关系；返回其他参见OpeDB::handleSearchUsr()
	int handleAddFriend(const char* perName, const char* name);
	//添加成功返回true 添加失败返回false
	int addFriend(const char* perName, const char* name);


signals:
public slots:
private:
	// connect to database
	QSqlDatabase m_db;
};

